"""Reset admin passwords for development.

This script updates the SQLite DB directly to set password of the admin users
to a known development value. Use only in local/dev environments.
"""

from __future__ import annotations

from sqlalchemy import create_engine, text

from app.core.security import get_password_hash


def main() -> None:
    hashed = get_password_hash("admin123")
    engine = create_engine("sqlite:///../n8ncrm.db")
    emails = ["administrator@example.com", "admin@example.com"]
    with engine.begin() as conn:
        for email in emails:
            result = conn.execute(
                text("UPDATE users SET hashed_password=:hp WHERE email=:email"),
                {"hp": hashed, "email": email},
            )
            print(f"Updated {result.rowcount} row(s) for {email}")


if __name__ == "__main__":
    main()
